@isTest
private class SalesPerformanceDataImportControllerTest {
    static testMethod void testMethod1() {


    	Id ReagentPerformance = Utils.getRecordTypeIdByDevNameAndObjName('ReagentPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent = new SalesPerformanceDataSheet__c(
    			RecordTypeId = ReagentPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '001234',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    			ActualSalesQ1__c = 2500,
    			ActualSalesQ2__c = 2500,
    			ActualSalesQ3__c = 2500,
    			ActualSalesQ4__c = 2500,

    			BudgetSales__c = 10000,
    			BudgetSalesQ1__c = 2500,
    			BudgetSalesQ2__c = 2500,
    			BudgetSalesQ3__c = 2500,
    			BudgetSalesQ4__c = 2500,

				LastYearSalesVolume__c = 8000,
				LastYearSalesVolumeQ1__c = 2000,
				LastYearSalesVolumeQ2__c = 2000,
				LastYearSalesVolumeQ3__c = 2000,
				LastYearSalesVolumeQ4__c = 2000

    		);


        Id ReagentPerformanceSum = Utils.getRecordTypeIdByDevNameAndObjName('ReagentPerformanceSum', 'SalesPerformanceDataSheet__c');

        SalesPerformanceDataSheet__c regentSum = new SalesPerformanceDataSheet__c(
                RecordTypeId = ReagentPerformanceSum,
                Year__c = System.today().year()+'年',
                
                Quarter__c = '1',
                Company__c = 'MKSW',
                EmployeeNumber__c = '001234',
                Name__c = '测试',
                JobCategory__c = '直销销售员',
                SalesMarket__c = '经销商',
                ReagentCategory__c = '迈克试剂',
                ActualSales__c = 10000,
                ActualSalesQ1__c = 2500,
                ActualSalesQ2__c = 2500,
                ActualSalesQ3__c = 2500,
                ActualSalesQ4__c = 2500,

                BudgetSales__c = 10000,
                BudgetSalesQ1__c = 2500,
                BudgetSalesQ2__c = 2500,
                BudgetSalesQ3__c = 2500,
                BudgetSalesQ4__c = 2500,

                LastYearSalesVolume__c = 8000,
                LastYearSalesVolumeQ1__c = 2000,
                LastYearSalesVolumeQ2__c = 2000,
                LastYearSalesVolumeQ3__c = 2000,
                LastYearSalesVolumeQ4__c = 2000

            );



    	Id InstrumentPerformance = Utils.getRecordTypeIdByDevNameAndObjName('InstrumentPerformance', 'SalesPerformanceDataSheet__c');
    	SalesPerformanceDataSheet__c equip = new SalesPerformanceDataSheet__c(
    			RecordTypeId = InstrumentPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '001234',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			InstrumentClasses__c = 'C800',
    			ActualQuantity__c = 100,
    			ActualQuantityQ1__c = 25,
    			ActualQuantityQ2__c = 25,
    			ActualQuantityQ3__c = 25,
    			ActualQuantityQ4__c = 25,

    			BudgetQuantity__c = 100,
    			BudgetQuantityQ1__c = 25,
    			BudgetQuantityQ2__c = 25,
    			BudgetQuantityQ3__c = 25,
    			BudgetQuantityQ4__c = 25


    		);
    	
    	Id ReagentIncrementalPerformance = Utils.getRecordTypeIdByDevNameAndObjName('ReagentIncrementalPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = ReagentIncrementalPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '001234',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			Category__c = '特殊项目',
    			ActualSales__c = 10000,
    			ActualSalesQ1__c = 2500,
    			ActualSalesQ2__c = 2500,
    			ActualSalesQ3__c = 2500,
    			ActualSalesQ4__c = 2500,

    			
				LastYearSalesVolume__c = 8000,
				LastYearSalesVolumeQ1__c = 2000,
				LastYearSalesVolumeQ2__c = 2000,
				LastYearSalesVolumeQ3__c = 2000,
				LastYearSalesVolumeQ4__c = 2000
    		);

    	Id AnnualIncrementPerformance = Utils.getRecordTypeIdByDevNameAndObjName('AnnualIncrementPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent_annual_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = AnnualIncrementPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '001234',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    			BudgetSales__c = 10000,

				LastYearSalesVolume__c = 8000
				

    		);
    	Id AgentIncrementPerformance = Utils.getRecordTypeIdByDevNameAndObjName('AgentIncrementPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c agent_annual_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = AgentIncrementPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '001234',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    		
    			BudgetSales__c = 10000,

				LastYearSalesVolume__c = 8000
				

    		);

    	insert new List<SalesPerformanceDataSheet__c>{regent,regentSum,regent_annual_increase,agent_annual_increase ,equip ,regent_increase };
    	
        Database.executeBatch(new SalePerformanceDataCalcBatch(System.today().year()+'年','1','MKSW') , 1);
        Database.executeBatch(new SalePerformanceDataCalcBatch(System.today().year()+'年','1','MKSW',true) , 1);

    	
    	SalesPerformanceDataImportController sip = new SalesPerformanceDataImportController();
    	sip.init();
    	Map<String,String> searchMap = new Map<String,String>();
    	searchMap.put('year', System.today().year()+'年');
    	searchMap.put('quater', '1');
    	searchMap.put('company', 'MKSW');
    	searchMap.put('workno', '001234');
    	searchMap.put('rtype', 'ReagentPerformance');
    	searchMap.put('otype', 'ReagentBudgetAdjust');
    	sip.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');

    	sip.searchDetail();
    	searchMap.put('sum', 'true');
        searchMap.put('rtype', 'ReagentPerformanceSum');
    	sip.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');
    	sip.searchDetail();


    	searchMap.put('rtype', 'InstrumentPerformance');
    	searchMap.put('otype', 'InstrumentPerformanceAdjust');
        searchMap.put('rtype', 'InstrumentPerformanceSum');
    	sip.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');

    	sip.searchDetail();

    	searchMap.put('rtype', 'ReagentIncrementalPerformance');
    	searchMap.put('otype', 'ReagentIncrementalPerformanceAdjust');
        searchMap.put('rtype', 'ReagentIncrementalPerformanceSum');
    	sip.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');
    	sip.searchDetail();

    	searchMap.put('rtype', 'AnnualIncrementPerformance');
    	searchMap.put('otype', 'AnnualIncrementPerformanceAdjust');
        searchMap.put('rtype', 'AnnualIncrementPerformanceSum');
    	sip.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');
    	sip.searchDetail();

    	

    	Map<String,Object> saveData = new Map<String,Object>();
    	saveData.put('Id', agent_annual_increase.Id);
    	saveData.put('Year__c', System.today().year()+'年');
    	saveData.put('Quarter__c', '1');
    	saveData.put('Company__c', 'MKSW');
    	saveData.put('EmployeeNumber__c', '001234');
    	saveData.put('Name__c', '测试');
    	saveData.put('JobCategory__c','直销销售员');
    	saveData.put('SalesMarket__c', '经销商');
    	saveData.put('ReagentCategory__c', '迈克试剂');
    	saveData.put('ActualSales__c', 10000);
    	saveData.put('BudgetSales__c', 10000);
    	saveData.put('LastYearSalesVolume__c', 10000);
    	List<Object>saveList = new List<Object>{saveData};
    	SalesPerformanceDataImportController.importData(EncodingUtil.urlEncode(JSON.serialize(saveList), 'UTF-8'),'AnnualIncrementPerformanceAdjust','1');

        sip.deleType = 'ReagentPerformanceSum';
        sip.deleCompany = 'MKSW';
        sip.deleteSum();


    }
}